using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using System.Collections.Generic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UIHeroFeatureTips : UIBaseWindow
    {
        /// <summary>
        /// 静态配置
        /// </summary>
        private static UICreateConfig _createConfig = new()
        {
            prefabName = nameof(UIHeroFeatureTips),
            layer = EUILayer.Pop,
        };

        /// <summary>
        /// 创建UI的配置
        /// </summary>
        public override IUICreateConfig createConfig => _createConfig;

        #region Template Generate,don't modify
        protected partial class UIB_UIHeroFeatureTips
        {
            #region ObjectBinding Generate 
            public IQIGame.Onigao.Framework.ExButton btn_Close { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textTitle { protected set; get; }
            public GameObject feature { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExButton>("btn_Close", out var __tbv0);
                this.btn_Close = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textTitle", out var __tbv1);
                this.textTitle = __tbv1;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("feature", out var __tbv2);
                this.feature = __tbv2;
            }

            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields & properties
        ListScrollAdapter<UIN_HeroFeatureOne> listFeature = null;

        HeroData heroData = null;
        private List<UD_HereFeature> listDataHeroFreature = null;

        protected UIB_UIHeroFeatureTips ui { get; set; }
        #endregion

        protected override void BeforeInit()
        {
            ui = new UIB_UIHeroFeatureTips();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this.listFeature = this.InitListScroll<UIN_HeroFeatureOne>(this.ui.feature, this.OnFeatureChanged);

            this.ui.btn_Close.onClick.AddListener(this.Close);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        protected override void OnDispose()
        {
            this.OnClearData();
        }

        private void OnClearData()
        {
            if (this.listDataHeroFreature != null)
            {
                foreach (var item in this.listDataHeroFreature)
                    item.Put2Pool();
            }
            this.listDataHeroFreature = null;
        }

        protected override void OnShow(UIBaseData data)
        {
            var d = data as UD_HeroFeatureTip;
            this.heroData = d.heroData;
            if (this.heroData == null)
                return;
            this.listDataHeroFreature = HeroModule.Instance.GetHeroFeatureCfgStars(this.heroData.cid, this.heroData.star);
            var list = this.listDataHeroFreature;
            this.listFeature.RefillCells(list.Count);
        }

        void OnFeatureChanged(UIN_HeroFeatureOne item, int index)
        {
            var listFeature = this.listDataHeroFreature;
            var csObj = listFeature[index];
            item.Show(csObj);
        }
    }
}
